package org.rain.bee.service.impl;

import org.rain.bee.dao.TbSysUserMapper;
import org.rain.bee.domain.TbSysUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.stereotype.Service;

@Service
public class CustomUserDetailsService implements UserDetailsService {

	@Autowired
	private TbSysUserMapper sysUser;
	
	//@Autowired
	//@Qualifier("BCryptPasswordEncoder")
	private BCryptPasswordEncoder encoder;

	@Override
	public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {

		TbSysUser user1 = sysUser.selectByPrimaryKey(1l);
		
		encoder = new BCryptPasswordEncoder();
		
		String ciperStr = ""+encoder.encode("user");//{bcrypt}

		UserDetails user = User.builder().username("user").password(ciperStr).roles("USER").authorities("USER").build();

		return new User(user.getUsername(), user.getPassword(), user.isEnabled(), user.isAccountNonExpired(), user.isCredentialsNonExpired(),
				user.isAccountNonLocked(), user.getAuthorities());
	}

}
